//#include "stdafx.h"
#include "Global_Function.h"
#include "JsonRpcSource.h"
#include "JsonRpcSocket.h"
#include "JsonRpcUtil.h"

namespace JsonRpc {


  JsonRpcSource::JsonRpcSource(int fd /*= -1*/, bool deleteOnClose /*= false*/) 
    : _fd(fd), _deleteOnClose(deleteOnClose), _keepOpen(false)
  {
  }

  JsonRpcSource::~JsonRpcSource()
  {
  }


  void
  JsonRpcSource::close()
  {
    if (_fd != -1) {
      JsonRpcUtil::log(2,"JsonRpcSource::close: closing socket %d.", _fd);
      JsonRpcSocket::close(_fd);
      JsonRpcUtil::log(2,"JsonRpcSource::close: done closing socket %d.", _fd);
      _fd = -1;
    }
    if (_deleteOnClose) {
      JsonRpcUtil::log(2,"JsonRpcSource::close: deleting this");
      _deleteOnClose = false;
      delete this;
    }
  }

} // namespace JsonRpc
